<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./layui/css/layui.css">
    <link rel="stylesheet" href="./css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body style="background-color: white">
<div class="layui-form layuimini-form">

    <div class="layui-form-item layui-anim-down">
        <label class="layui-form-label">商品编号</label>
        <div class="layui-input-block">
            <span style="line-height: 38px;color: teal">${product.productId}</span>
            <input type="hidden" name="productId" value="${product.productId}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="productName" placeholder="请输入商品名称" value="${product.productName}"
                   class="layui-input" autocomplete="off" lay-verify="required">
        </div>
    </div>


    <div class="layui-form-item" style="display: none;">
        <label class="layui-form-label required">商品类别</label>
        <div class="layui-input-block">
            <input type="text" name="productType" disabled="disabled" placeholder="请输入商品类别" value="${product.productType}"
                   class="layui-input" autocomplete="off" lay-verify="required">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">商品类别名</label>
        <div class="layui-input-block">
            <input type="text" name="dictItemName" placeholder="请输入商品类别名" value="${product.dictItemName}"
                   class="layui-input" autocomplete="off" lay-verify="required">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>

</div>

<script src="./layui/layui.js"></script>

<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            $ = layui.$;


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: './updateProduct',
                type: 'post',
                data: data.field,
                success: function (data) {
                    if (data.status == 'error') {
                        layer.msg('失败', {icon: 5});//失败的表情
                        return;
                    } else {
                        layer.msg('成功', {
                            icon: 6,//成功的表情
                            time: 1000, //1秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            layer.closeAll();
                            window.parent.location.reload();
                        });
                    }
                },
                error: function (e) {
                    layer.msg("失败",
                        {
                            //失败的表情
                            icon: 5
                        },
                        function () {
                            location.reload();
                        });
                    console.log(e);
                },
            });
            return false;
        });

    });
</script>
</body>
</html>